/**
 * 为泛型只读集合提供基类。
 * License: BSD
 * Authors: Lucifer (786325481@QQ.com)
 * Copyright: Copyright (C) 2008 Lucifer. All rights reserved.
 */
module system.collections.objectmodel.ReadOnlyListCollection;

import system.Exception;
import system.collections.IList;
import system.collections.ICollection;
import system.collections.IEnumerable;
import system.collections.IEnumerator;
import system.collections.IEqualityComparer;
import system.collections.EqualityComparer;

public class ReadOnlyListCollection(T) : IList!(T), ICollection!(T), IEnumerable!(T)
{
	private IList!(T) list;

	public this(IList!(T) list)
	in
	{
		assert( list !is null );
	}
	body
	{
		this.list = list;
	}

	/* ***************************************************
	 * 实现ICollection(T)接口
	 * ***************************************************/
	public final bool isEmpty()
	{
		return this.list.isEmpty();
	}

	public final int count()
	{
		return this.list.count();
	}

	public final bool isReadOnly()
	{
		return true;
	}

	public final bool add(T item)
	{
		throw new NotSupportedException();
	}

	public final void clear()
	{
		throw new NotSupportedException();
	}

	public final bool remove(T item)
	{
		throw new NotSupportedException();
		return false;
	}

	public final bool contains(T item)
	{
		return this.list.contains(item);
	}

	public final void toArray(T[] array)
	in
	{
		assert( array !is null );
	}
	body
	{
		return this.list.toArray(array);
	}

	/* ********************************************************
	 * 实现IEnumerable(T)接口
	 * ********************************************************/
	public final IEnumerator!(T) getEnumerator()
	{
		return this.list.getEnumerator();
	}

	public final int opApply (int delegate (ref T value) dg)
	{
		return this.list.opApply(dg);
	}

	/* *********************************************************
	 * 实现IList(T)接口
	 * *********************************************************/
	public final T opIndex(int index)
	{
		return this.list.opIndex(index);
	}

	public final void opIndexAssign(T item, int index)
	{
		throw new NotSupportedException();
	}

	public final int indexOf(T item)
	{
		return this.list.indexOf(item);
	}

	public final void insert(int index, T item)
	{
		throw new NotSupportedException();
	}

	public final void removeAt(int index)
	{
		throw new NotSupportedException();
	}

	/* ********************************************************
	 * 扩展方法
	 * ********************************************************/
	protected IList!(T) items()
	{
		return this.list;
	}
}
